classdef TestDotsComputableFunction < dotsTestCase
    
    methods
        function self = TestDotsComputableFunction(name)
            self = self@dotsTestCase(name);
        end
        
        function setUp(self)
            self.setUp@dotsTestCase;
            topsDataLog.flushAllData;
        end
        
        function tearDown(self)
            topsDataLog.flushAllData;
            self.tearDown@dotsTestCase;
        end
        
        function testComputeResult(self)
            computable = dotsComputableFunction();
            fun = @(input)numel(input);
            computable.computeFunction = fun;
            
            input = 1:10;
            computable.computeInputs = {input};
            expectedResult = numel(input);
            result = computable.compute;
            assertEqual(result, expectedResult, ...
                'compute() result should match expected result')
            assertEqual(computable.computeResult, expectedResult, ...
                'computeResult property should match expected result')
        end
        
        function testRecompute(self)
            computable = dotsComputableFunction();
            fun = @(input)numel(input);
            computable.computeFunction = fun;
            
            computable.recomputeInterval = 0;
            computable.prepareToCompute;
            
            input = 1:10;
            computable.computeInputs = {input};
            expectedResult = numel(input);
            computable.mayComputeNow(0);
            assertEqual(computable.computeResult, expectedResult, ...
                'first re-compute() result should match computeResult property')
            
            input = 1:100;
            computable.computeInputs = {input};
            expectedResult = numel(input);
            computable.mayComputeNow(0);
            assertEqual(computable.computeResult, expectedResult, ...
                're-re-compute() result should match computeResult property')
        end
    end
end